package com.site.wisdom_construction.controller.iotModule;

import com.site.wisdom_construction.entity.iotModule.TowerCraneBasic;
import com.site.wisdom_construction.entity.iotModule.TowerCraneRealtime;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.service.iotModule.TowerCraneBasicService;
import com.site.wisdom_construction.service.iotModule.TowerCraneRealtimeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/9/1
 * @Description
 */
@Api(tags = "塔吊实时数据接口")
@RestController
@RequestMapping("TowerCraneRealtime")
@CrossOrigin
public class TowerCraneRealtimeController {
    @Autowired
    private TowerCraneRealtimeService towerCraneRealtimeService;

    @Autowired
    private TowerCraneBasicService towerCraneBasicService;

    @ApiOperation(value = "根据设备id查询最新塔机实时数据", notes = "必传参数:deviceId")
    @PostMapping("/findTowerCraneRealtimeByDeviceId")
    public OneDataResult findTowerCraneRealtimeByDeviceId(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(towerCraneRealtimeService.findTowerCraneRealtimeByDeviceId(map));
        return oneDataResult;
    }

    @ApiOperation(value = "根据设备id查询最新塔机实时数据", notes = "必传参数:deviceId")
    @PostMapping("/findTowerCraneRealtime")
    public OneDataResult findTowerCraneRealtime(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(towerCraneRealtimeService.findTowerCraneRealtime(map));
        return oneDataResult;
    }

    @ApiOperation(value = "群吊回转角度", notes = "必传参数:deviceId")
    @PostMapping("/selectTowerCraneRealtime")
    public OneDataResult selectTowerCraneRealtime(@RequestBody Map map){
        OneDataResult oneDataResult = new OneDataResult();
        List<TowerCraneRealtime> towerCraneRealtimeList = new ArrayList<>();
        List<TowerCraneBasic> towerCraneBasicList = towerCraneBasicService.selectTowerCraneBasic(map);
        for (int i=0;i<towerCraneBasicList.size();i++){
            map.put("deviceId",towerCraneBasicList.get(i).getDeviceId());
            TowerCraneRealtime towerCraneRealtime = towerCraneRealtimeService.findTowerCraneRealtimeByDeviceIdI(map);
            towerCraneRealtimeList.add(towerCraneRealtime);
        }
        oneDataResult.setData(towerCraneRealtimeList);
        return oneDataResult;
    }
}
